/*
 * @Author: CodeHare
 * @Date: 2023-10-27 14:58:07
 * @LastEditors: CodeHare
 * @LastEditTime: 2023-10-27 20:54:21
 * @Description: 安装商角色主入口
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/components/app_permission/permission_widget.dart';
import 'package:yt_devops/pages/site/site_setting/siet_elec_price_setting/site_mains_elec_detail/keep_aliver_wrapper.dart';
import 'package:yt_devops/pages/site/site_view.dart';
import 'package:yt_devops/pages/site/widgets/home_statistics.dart';
import 'package:yt_devops/utils/alarm_util.dart';
import 'package:yt_devops/utils/constants/permission_page_constant.dart';
import 'package:yt_devops/utils/enums.dart';
import 'package:yt_devops/utils/func_utils.dart';

class MainHomeController extends GetxController with GetTickerProviderStateMixin{
  int selectedIndex = 0;
  TabController? tabController;
  List<Widget> homeTabviewChildren = [];
  bool firstIsStatic = false;
  List<Widget> operationTabviewChildren = [];///运维tabview
  @override
  void onInit() {
    super.onInit();
    tabController = TabController(length: 4, vsync: this);
    if(!FuncUtils.isPassAuthority([PermissionConstant.homeSiteList])){
      homeTabviewChildren.add( PermissionWidget(
          permissionStringList: const [
            PermissionConstant.homeSiteList
          ],
          child: KeepAliveWrapper(
            SiteHomePage(),
          )),);
    }
    if(!FuncUtils.isPassAuthority([PermissionConstant.homeStatic])){
      if(homeTabviewChildren.isEmpty){
        firstIsStatic = true;///如果homeTabviewChildren为空则说明第一个页面是统计
      }
      homeTabviewChildren.add(const PermissionWidget(permissionStringList: [
        PermissionConstant.homeStatic
      ], child: KeepAliveWrapper(HomeStatistics())));
    }
    Log.d('homeTabviewChildren===' + homeTabviewChildren.length.toString());
  }

  @override
  void onReady() {

  }

  @override
  void onClose() {}

  onItemTapped(index) {
    selectedIndex = index;
    tabController!.animateTo(index);
    if (index == 1) {
      AlarmUtil.fromModule = AlarmFromWhereType.allSites.value;
    }
    update();
  }
}
